﻿<?php
namespace Home\Controller;
use Think\Controller;
class CallbackController extends Controller {
    public function index(){
		$gateWary="";
		$eMail='';
		$payId='';
		$payKey='';
		$retUrl="http://".$_SERVER["HTTP_HOST"]."/Callback";
		$d3PayOrderId = I('get.d3PayOrderId');
		$orderId =I('get.orderId');
		$realMoney = I('get.realMoney');
		$payStatus = I('get.payStatus');
		$sign = I('get.sign');
	if ($payStatus==1){
	  $signstr=$d3PayOrderId . '&' . $orderId . '&' . $realMoney . '&' . $payStatus . '&' . $payKey;//签名原串
	  if ($sign==strtoupper(md5($signstr))){

	     $list=M('withpay')->where(array('orderid' => $orderId,'paystatus' => 0))->find();
	     if($list){
	         $time=time();
	         M('user')->startTrans();
	         $data2=array();
	         $data2['paytime']=$time;
	         $data2['paystatus']=1;

	         $list1=M('withpay')->where(array('orderid' => $orderId))->data($data2)->save();
	         $list2=M('user')->where(array('Id' => $list['uid']))->setInc('monery',$list['gamemoney']);
			$list2=M('user')->where(array('Id'	=>	$list['uid']))->setInc('payall',$list['gamemoney']);

	          $data2=array();
	          $data2['type']=1;//2减少
	          $data2['amount']=$list['gamemoney'];
	          $data2['info']=$orderId.'充值';
	          $data2['time']=$time;
	          $data2['uid']=$list['uid'];
	          $list3=M('monery')->data($data2)->add();

	          if($list1 && $list2 && $list3) {
	             M('user')->commit();
	             echo "success";
	          }else{
	            M('user')->rollback();
	          }
	      }
	    }
	}
	}
}
